﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SN.Models;
namespace SN.Report
{
    public partial class JYFormulaDlg : Form
    {
        public FormTemp FrmTemp;
        public int currSelectCellX= 0;
        public int currSelectCellY = 0;
        public int x = 0, y = 0;
        private T_ZBZD zbzd;

        public T_ZBZD Zbzd
        {
            get { return zbzd; }
            set { zbzd = value; }
        }
        public JYFormulaDlg()
        {
            InitializeComponent();
        }

        public static uint ParseRGB(Color color)
        {
            return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
        }
        private void JYFormulaDlg_Load(object sender, EventArgs e)
        {
            this.Text = zbzd.ZBZD_ZBBH + this.Text;
            this.richTextBox1.Text = zbzd.ZBZD_JYFormula; //校验公式
            x = Convert.ToInt32(textBox_x.Text);
            y = Convert.ToInt32(textBox_y.Text);
            string sZbbh = FrmTemp.cellControl1.axCell.GetCellString(currSelectCellX + x, currSelectCellY + y, FrmTemp.cellControl1.axCell.GetCurSheet());
            if (this.richTextBox1.Text.Length == 0)
            {
               
                //this.richTextBox1.Text = ">" + sZbbh;
                //this.richTextBox1.Select(this.richTextBox1.Text.Length, 1);
                //this.richTextBox1.Focus();
               
            }
            else
            {//添加多个公式
            //    this.richTextBox1.Text += "\r\n>" + sZbbh;
            //    this.richTextBox1.Select(this.richTextBox1.Text.Length, 1);
            //    this.richTextBox1.Focus();
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string lsFormula = this.richTextBox1.Text.Trim();
            //判断字符长度不能超过1000
            if (lsFormula.Length > 1000)
            {
                MessageBox.Show("公式太长啦!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //if (lsFormula.Length <=1)
            //{
            //    MessageBox.Show("公式太短啦!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}

            int iSheet = FrmTemp.cellControl1.axCell.GetCurSheet();
            int myColor = (int)ParseRGB(Color.Yellow); //设置成黄色
            FrmTemp.cellControl1.axCell.SetCellBackColor(FrmTemp.startCol, FrmTemp.startRow, iSheet, myColor);
            //写开始行 与开始列 （即指标公式所在的行与列)
            //FrmTemp.cellControl1.axCell.SetCellTip(FrmTemp.startCol, FrmTemp.startRow, iSheet, this.richTextBox1.Text);
            //保存数据
            zbzd.ZBZD_JYFormula = this.richTextBox1.Text.Trim();
            zbzd.Attach();
            SN.Data.DBUtility.DB.Save<T_ZBZD>(zbzd);

            Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += ">";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "<";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "+";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "-";
        }

        private void button8_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "*";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "/";
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        
    }
}
